import store from '../../../store/store.js';
import * as ActionTypes from '../../../constants/constants.js';
import { isUser, isWxUser, path, saveData, loadData, removeData, } from '../../../util/utils.js';
import request from '../../../api/request.js';

export async function getUserLogin(options) {
  const { dispatch, } = this.props;
  const res = await request.getUserLogin(options);
  return new Promise((resolve, reject) => {
    if (res.state == 1) {
      dispatch({
        type: ActionTypes.GET_USER_INFO,
        data: res.data,
      });
      resolve(res);
    } else {
      reject(res);
    }
  });
}

export async function sendYzm(options) {
  const res = await request.sendYzm(options);
  return new Promise((resolve, reject) => {
    if (res.state == 1) {
      resolve(res);
    } else {
      reject(res);
    }
  });
}

export async function getUpdateUser(options) {
  const { dispatch, } = this.props;
  const res = await request.getUpdateUser(options);
  return new Promise((resolve, reject) => {
    if (res.state == 1) {
      if (options.method == 'info') {
        dispatch({
          type: ActionTypes.GET_USER_INFO,
          data: res.data,
        });
      }
      resolve(res);
    } else {
      reject(res);
    }
  });

}
